package com.sca.api.system.factory;
import com.sca.api.system.RemoteUserService;
import com.sca.api.system.domain.domain.SysUser;
import com.sca.api.system.model.LoginUser;
import com.sca.core.common.domain.R;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @Author: denglei
 * @Date: 2022/2/28 16:57
 * @Description:用户服务降级处理
 */
@Component
@Slf4j
public class RemoteUserFallbackFactory  implements FallbackFactory<RemoteUserService> {
    @Override
    public RemoteUserService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public R<LoginUser> getUserInfo(String username, String source)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> registerUserInfo(SysUser sysUser, String source)
            {
                return R.fail("注册用户失败:" + throwable.getMessage());
            }
        };
    }
}
